﻿
Partial Class Tools_SimilText
    Inherits MyUI.PageBaseApp
    Dim ti As SimilText.ArchiveData


    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        ti = SimilText.ArchiveData.GetData(5)

    End Sub


    Protected Sub BtnDerDictionary_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnDerDictionary.Click

        Dim d As New SimilText.Tools.Dictionary

        d.StemmingFile = ti.IndexesPath & ti.StemmingFile
        d.StemmingDBToText()

    End Sub


    Protected Sub Btnarchivia_Click(sender As Object, e As System.EventArgs) Handles Btnarchivia.Click
        'Dim a As New SimilText.ArchiveText(ti)
        ''Dim post = DB.TabQuery_Post.Where.ToList
        'Dim post = DB.TAB.AccountPost.NotifyChanged(False).Limit(10000000).ToList


        '' a.Open()
        'Dim ct = 1
        'For Each p In post

        '    If ct Mod 10000 = 0 Then
        '        UI.Page.WriteLog(ct)
        '    End If

        '    a.Text = p.Post_Text
        '    a.Id = p.Id
        '    a.EditAttribute(p.Account_Id, 0)
        '    a.EditAttribute(Utils.Conv.ToTimeStamp(p.Pubb_Date), 1)
        '    a.Archive()

        '    ct += 1
        'Next

        'a.Close()


        'ArchiveText("prova", 1)

    End Sub

    Protected Sub BtnView_Click(sender As Object, e As System.EventArgs) Handles BtnView.Click
        Dim a As New SimilText.CompareText(ti)

        a.Text1 = Me.Txt1.Text
        a.Text2 = Me.Txt2.Text

        Dim r = a.Compare

        Me.Literal1.Text = r.Matches(0).Accuracy

    End Sub

    Public Function ArchiveText(ByVal Text As String, ByVal Id As UInteger) As Integer
        Dim a As New SimilText.ArchiveText(ti)

        'a.Open()
        a.Text = Text
        a.Id = Id
        a.Archive()
        a.Close()

        Return 1

    End Function


    Public Function ArchiveTextAttr(ByVal Text As String, ByVal Id As UInteger, ByVal Attribute As UInteger) As Integer
        Dim a As New SimilText.ArchiveText(ti)

        'a.Open()
        a.Text = Text
        a.Id = Id
        a.EditAttribute(Attribute, 0)
        a.Archive()
        a.Close()

        Return 1

    End Function

    Public Function ArchiveTextDate(ByVal Text As String, ByVal Id As UInteger, ByVal DateText As Date) As Integer
        Dim a As New SimilText.ArchiveText(ti)

        'a.Open()
        a.Text = Text
        a.Id = Id
        a.EditAttribute(Utils.Conv.ToTimeStamp(DateText), 1)
        a.Archive()
        a.Close()

        Return 1

    End Function

    Public Function ArchiveTextAttrDate(ByVal Text As String, ByVal Id As UInteger, ByVal Attribute As UInteger, ByVal DateText As Date) As Integer
        Dim a As New SimilText.ArchiveText(ti)

        ' a.Open()
        a.Text = Text
        a.Id = Id
        a.EditAttribute(Attribute, 0)
        a.EditAttribute(Utils.Conv.ToTimeStamp(DateText), 1)
        a.Archive()
        a.Close()

        Return 1

    End Function

    '---------------------------------------------------------------------------

    Public Function Compare2Text(ByVal key As String, ByVal Text1 As String, ByVal Text2 As String) As SimilText.FindResult
        Dim c As New SimilText.CompareText(ti)

        c.Text1 = Text1
        c.Text2 = Text2
        c.Compare()

        Return c.Result

    End Function

    'key
    'testo
    'dizionario
    'max perc diff (auto def, solo se minore lo usa)

    ' attributi


    Public Function FindSimilarText(ByVal Key As String, ByVal Text As String, ByVal UseDictionary As String, ByVal PercMaxDiff As String) As SimilText.FindResult
        Dim f As New SimilText.FindSimilarText(ti)

        f.Text = Text
        f.RankMin = 80
        'f.UseDictionary = True
        'f.AutoPercMaxDiff = False

        f.Find()

        Return f.Result

    End Function


    Public Function FindSimilarTextFilter(ByVal Key As String, ByVal Text As String, ByVal UseDictionary As String, ByVal PercMaxDiff As String, ByVal ValMin As String, ByVal ValMax As String, ByVal DateMin As String, ByVal DateMax As String) As SimilText.FindResult
        Dim f As New SimilText.FindSimilarText(ti)

        f.Text = Text
        f.RankMin = 100
        'f.UseDictionary = False
        'f.AutoPercMaxDiff = False


        'f.AddFilter(ValMin, ValMax, ArchiveIndexType.Attribute1)
        'r.AddFilter(ValMin, ValMax, ArchiveIndexType.Attribute1)
        'r.AddFilter(TextTools.DateToUInt(DateMin), TextTools.DateToUInt(DateMax), ArchiveIndexType.Attribute2)

        f.Find()

        Return f.Result

    End Function

End Class
